<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>07canvas绘制虚线</title>
</head>
<style>
    canvas{
        border:1px solid #ccc;
    }
</style>
<body>
<canvas width="600"height="400"></canvas>
<script>
    var myCanvas =document.querySelector('canvas');
    var ctx=myCanvas.getContext('2d');
//    画线
    ctx.moveTo(100,100.5);
    ctx.lineTo(300,100.5);
    //【5,10,15】数组是用来描述你的排列方式
    ctx.setLineDash([5,10,15]);
    /*获取虚线的排列方式 获取的是不重复那一段的排列方式*/
    console.log(ctx.getLineDash());
    /*设置虚线偏移量 （负值向右偏移，正值向左偏移）*/
    ctx.lineDashOffset=50;
    ctx.stroke();
</script>
</body>
</html>
